This is more robust in the face of msys terminals and otherwise helps share more
dependencies!
Closes #4166
version = "0.21.0"
dependencies = [
"advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cargotest 0.1.0",
"crates-io 0.10.0",
"memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "atty"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "backtrace"
version = "0.3.2"
"checksum advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e06588080cb19d0acb6739808aafa5f26bfb2ca015b2b6370028b44cf7cb8a9a"
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
+"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159"
"checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76"
"checksum backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0d842ea781ce92be2bf78a9b38883948542749640b8378b3b2f03d1fd9f1ff"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
path = "src/cargo/lib.rs"
[dependencies]
+atty = "0.2"
crates-io = { path = "src/crates-io", version = "0.10" }
crossbeam = "0.2"
curl = "0.4.6"
use std::fmt;
use std::io::prelude::*;
-use termcolor::{self, StandardStream, Color, ColorSpec, WriteColor};
+use atty;
use termcolor::Color::{Green, Red, Yellow};
+use termcolor::{self, StandardStream, Color, ColorSpec, WriteColor};
use util::errors::CargoResult;
impl ColorChoice {
fn to_termcolor_color_choice(&self) -> termcolor::ColorChoice {
- return match *self {
+ match *self {
ColorChoice::Always => termcolor::ColorChoice::Always,
ColorChoice::Never => termcolor::ColorChoice::Never,
- ColorChoice::CargoAuto if isatty() => termcolor::ColorChoice::Auto,
- ColorChoice::CargoAuto => termcolor::ColorChoice::Never,
- };
-
- #[cfg(unix)]
- fn isatty() -> bool {
- extern crate libc;
-
- unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
- }
-
- #[cfg(windows)]
- fn isatty() -> bool {
- extern crate kernel32;
- extern crate winapi;
-
- unsafe {
- let handle = kernel32::GetStdHandle(winapi::STD_ERROR_HANDLE);
- let mut out = 0;
- kernel32::GetConsoleMode(handle, &mut out) != 0
+ ColorChoice::CargoAuto => {
+ if atty::is(atty::Stream::Stderr) {
+ termcolor::ColorChoice::Auto
+ } else {
+ termcolor::ColorChoice::Never
+ }
}
}
}
#[macro_use] extern crate scoped_tls;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate serde_json;
+extern crate atty;
extern crate crates_io as registry;
extern crate crossbeam;
extern crate curl;